package thread;

//测试守护线程
//上帝守护你
public class TestDeamon {

    public static void main(String[] args) {
        God god = new God();
        You1 y = new You1();

        Thread thread = new Thread(god);
        thread.setDaemon(true); //默认为false,表示为用户线程，true为守护线程

        thread.start();

        new Thread(y).start();

    }
}



//上帝
class God implements Runnable{

    @Override
    public void run() {
        while (true){
            System.out.println("god protects you");
        }
    }
}

//你
class You1 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 365; i++) {
            System.out.println("活着");
        }
        System.out.println("goodbye world!");
    }
}